#include "GBackGround.h"

LPDIRECT3DTEXTURE9	CBackGround::_sightDay;	
LPDIRECT3DTEXTURE9	CBackGround::_sightNight;
void CBackGround::InitResoure()
{
	_sightDay=CSprites::LoadTexture(SIGHT_DAY,0);
	_sightNight=CSprites::LoadTexture(SIGHT_NIGHT,0);
}
CBackGround::CBackGround(void)
{
}
CBackGround::CBackGround(int left, int top, int kind)
{
	_typeObj=-1;
	_layer=0;

	_pRECT->left=left;
	_pRECT->top=top;
	_kind=kind;
	_isActive=true;
	_id=countObj++;
	_status=0;
	infoDaw.index=0;
	infoDaw.lastTime=GetTickCount();
	switch(_kind)
	{
	case 0://Cloud
		_pRECT->right=_pRECT->left+CLOUD_W;
		_pRECT->bottom=top+CLOUD_H;
		infoDaw.spriteCount=3;
		infoDaw.mapImage=1;
		infoDaw.deltaXSprite=0;
		infoDaw.deltaYSprite=0;
		infoDaw.width=CLOUD_W;
		infoDaw.height=CLOUD_H;
		infoDaw.timeDelay=400;

		break;
	case 1://Fence
		_pRECT->right=_pRECT->left+FENCE_W;
		_pRECT->bottom=_pRECT->top+FENCE_H;
		infoDaw.mapImage=1;
		infoDaw.spriteCount=1;
		infoDaw.deltaXSprite=0;
		infoDaw.deltaYSprite=45;
		infoDaw.width=FENCE_W;
		infoDaw.height=FENCE_H;
		infoDaw.timeDelay=0;
		break;
	case 2://Grass
		_pRECT->right=_pRECT->left+GRASS_W;
		_pRECT->bottom=_pRECT->top+GRASS_H;
		infoDaw.mapImage=1;
		infoDaw.spriteCount=2;
		infoDaw.deltaXSprite=0;
		infoDaw.deltaYSprite=80;
		infoDaw.width=GRASS_W;
		infoDaw.height=GRASS_H;
		infoDaw.timeDelay=140;
		break;	
	case 3://Big Tree
		_pRECT->right=_pRECT->left+B_TREE_W;
		_pRECT->bottom=_pRECT->top+B_TREE_H;
		infoDaw.mapImage=1;
		infoDaw.spriteCount=1;
		infoDaw.deltaXSprite=0;
		infoDaw.deltaYSprite=112;
		infoDaw.width=B_TREE_W;
		infoDaw.height=B_TREE_H;
		infoDaw.timeDelay=0;
		break;	
	case 4://Small Tree
		_pRECT->right=_pRECT->left+S_TREE_W;
		_pRECT->bottom=_pRECT->top+S_TREE_H;
		infoDaw.mapImage=1;
		infoDaw.spriteCount=1;
		infoDaw.deltaXSprite=55;
		infoDaw.deltaYSprite=112;
		infoDaw.width=S_TREE_W;
		infoDaw.height=S_TREE_H;
		infoDaw.timeDelay=0;
		break;
	case 5://Arrow
		_pRECT->right=_pRECT->left+ARROW_W;
		_pRECT->bottom=_pRECT->top+ARROW_H;
		infoDaw.mapImage=1;
		infoDaw.spriteCount=1;
		infoDaw.deltaXSprite=0;
		infoDaw.deltaYSprite=203;
		infoDaw.width=ARROW_W;
		infoDaw.height=ARROW_H;
		infoDaw.timeDelay=0;
		break;
	case 6://Cactus
		_pRECT->right=_pRECT->left+CACTUS_W;
		_pRECT->bottom=_pRECT->top+CACTUS_H;
		infoDaw.mapImage=1;
		infoDaw.spriteCount=1;
		infoDaw.deltaXSprite=0;
		infoDaw.deltaYSprite=240;
		infoDaw.width=CACTUS_W;
		infoDaw.height=CACTUS_H;
		infoDaw.timeDelay=0;
		break;
	case 7://Mountain
		_pRECT->right=_pRECT->left+MOUNTAIN_W;
		_pRECT->bottom=_pRECT->top+MOUNTAIN_H;
		infoDaw.mapImage=1;
		infoDaw.spriteCount=1;
		infoDaw.deltaXSprite=0;
		infoDaw.deltaYSprite=400;
		infoDaw.width=MOUNTAIN_W;
		infoDaw.height=MOUNTAIN_H;
		infoDaw.timeDelay=0;
		break;
	case 8://transparent mast
		_pRECT->right=_pRECT->left+T_MAST_W;
		_pRECT->bottom=_pRECT->top+T_MAST_H;
		infoDaw.mapImage=1;
		infoDaw.spriteCount=1;
		infoDaw.deltaXSprite=341;
		infoDaw.deltaYSprite=0;
		infoDaw.width=T_MAST_W;
		infoDaw.height=T_MAST_H;
		infoDaw.timeDelay=0;
		break;
	case 9://normal mast
		_layer=2;
		_pRECT->right=_pRECT->left+MAST_W;
		_pRECT->bottom=_pRECT->top+MAST_H;
		infoDaw.mapImage=1;
		infoDaw.spriteCount=1;
		infoDaw.deltaXSprite=372;
		infoDaw.deltaYSprite=0;
		infoDaw.width=MAST_W;
		infoDaw.height=MAST_H;
		infoDaw.timeDelay=0;
		break;
	case 10://cloud
		_pRECT->right=_pRECT->left+CLOUD_W;
		_pRECT->bottom=_pRECT->top+CLOUD_H;
		infoDaw.mapImage=2;
		infoDaw.spriteCount=3;
		infoDaw.deltaXSprite=0;
		infoDaw.deltaYSprite=0;
		infoDaw.width=CLOUD_W;
		infoDaw.height=CLOUD_H;
		infoDaw.timeDelay=400;
		break;
	case 11://grass
		_pRECT->right=_pRECT->left+GRASS_W;
		_pRECT->bottom=_pRECT->top+GRASS_H+20;
		infoDaw.mapImage=2;
		infoDaw.spriteCount=3;
		infoDaw.deltaXSprite=0;
		infoDaw.deltaYSprite=50;
		infoDaw.width=GRASS_W;
		infoDaw.height=GRASS_H+20;
		infoDaw.timeDelay=100;
		break;
	case 12://Lamp
		_pRECT->right=_pRECT->left+LAMP_W;
		_pRECT->bottom=_pRECT->top+LAMP_H;
		infoDaw.mapImage=2;
		infoDaw.spriteCount=3;
		infoDaw.deltaXSprite=0;
		infoDaw.deltaYSprite=140;
		infoDaw.width=LAMP_W;
		infoDaw.height=LAMP_H;
		infoDaw.timeDelay=200;
		break;
	case 13://Bush
		_pRECT->right=_pRECT->left+BUSH_W;
		_pRECT->bottom=_pRECT->top+BUSH_H;
		infoDaw.mapImage=2;
		infoDaw.spriteCount=1;
		infoDaw.deltaXSprite=0;
		infoDaw.deltaYSprite=250;
		infoDaw.width=BUSH_W;
		infoDaw.height=BUSH_H;
		infoDaw.timeDelay=0;
		break;
	case 14://mountain
		_pRECT->right=_pRECT->left+MOUNTAIN_W;
		_pRECT->bottom=_pRECT->top+MOUNTAIN_H;
		infoDaw.mapImage=2;
		infoDaw.spriteCount=1;
		infoDaw.deltaXSprite=0;
		infoDaw.deltaYSprite=370;
		infoDaw.width=MOUNTAIN_W;
		infoDaw.height=MOUNTAIN_H;
		infoDaw.timeDelay=0;
		break;
	case 15://castle
		_pRECT->right=_pRECT->left+CASTLE_W;
		_pRECT->bottom=_pRECT->top+CASTLE_H;
		infoDaw.mapImage=2;
		infoDaw.spriteCount=1;
		infoDaw.deltaXSprite=400;
		infoDaw.deltaYSprite=0;
		infoDaw.width=CASTLE_W;
		infoDaw.height=CASTLE_H;
		infoDaw.timeDelay=0;
		break;
	case 16://Star
		_pRECT->right=_pRECT->left+STAR_W;
		_pRECT->bottom=_pRECT->top+STAR_H;
		infoDaw.mapImage=2;
		infoDaw.spriteCount=4;
		infoDaw.deltaXSprite=0;
		infoDaw.deltaYSprite=520;
		infoDaw.width=STAR_W;
		infoDaw.height=STAR_H;
		infoDaw.timeDelay=100;
		break;
	case 17://Wall
		_pRECT->right=_pRECT->left+WALL_W;
		_pRECT->bottom=_pRECT->top+WALL_W;
		infoDaw.mapImage=4;
		infoDaw.spriteCount=1;
		infoDaw.deltaXSprite=350;
		infoDaw.deltaYSprite=300;
		infoDaw.width=WALL_W;
		infoDaw.height=WALL_H;
		infoDaw.timeDelay=0;
		break;
	case 18://Wall
		_pRECT->right=_pRECT->left+WALL_W;
		_pRECT->bottom=_pRECT->top+WALL_H;
		infoDaw.mapImage=4;
		infoDaw.spriteCount=1;
		infoDaw.deltaXSprite=350;
		infoDaw.deltaYSprite=400;
		infoDaw.width=WALL_W;
		infoDaw.height=WALL_H;
		infoDaw.timeDelay=0;
		break;
	}
}

void CBackGround::Draw(int VirtualLeft,int Style)
{
	RECT rec;
	if(infoDaw.timeDelay!=0&&GetTickCount()-infoDaw.lastTime>infoDaw.timeDelay)
	{
		infoDaw.lastTime=GetTickCount();
		infoDaw.index=(infoDaw.index+1)%infoDaw.spriteCount;

	}
	rec.left=infoDaw.deltaXSprite+(infoDaw.index*infoDaw.width);
	rec.top=infoDaw.deltaYSprite;
	rec.bottom=rec.top+infoDaw.height;
	rec.right=rec.left+infoDaw.width;
	CSprites::_spriteHandler->Begin(D3DXSPRITE_ALPHABLEND);
	D3DXVECTOR3	position((float)(_pRECT->left-VirtualLeft),(float)_pRECT->top,0);
	LPDIRECT3DTEXTURE9	_image;
	if(infoDaw.mapImage==1)
		_image=_sightDay;
	else
		_image=_sightNight;
	CSprites::_spriteHandler->Begin(D3DXSPRITE_ALPHABLEND);
	CSprites::_spriteHandler->Draw(	_image,
		&rec,
		NULL,
		&position,
		D3DCOLOR_XRGB(255,255,255));
	CSprites::_spriteHandler->End();
}
int CBackGround::Move()
{
	return 0;
}
void CBackGround::Collision(Object *Ob)
{
}
CBackGround::~CBackGround(void)
{
}
